# Maintainer: Andrew Sun <adsun701@gmail.com>

_pyname=PyStemmer
_realname=pystemmer
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.2.0.1
pkgrel=2
pkgdesc="Snowball stemming algorithms, for information retrieval (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/snowballstem/pystemmer/"
license=('MIT' 'BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-libstemmer")
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('9f3b366f1ed06b49dc1868bf0aefd884423db80f3431be442d0f993e448cc67b')

prepare() {
  cd "${srcdir}"/${_pyname}-${pkgver}

  rm -rf "${srcdir}"/python-build-${MSYSTEM} | true
  cp -r "${srcdir}"/"${_pyname}-${pkgver}" "${srcdir}"/"python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYSTEMMER_SYSTEM_LIBSTEMMER=1 ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  PYSTEMMER_SYSTEM_LIBSTEMMER=1 \
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
